﻿<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing" 
    xmlns:common="clr-namespace:StoryMaker.Common;assembly=StoryMaker.Common"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:WPF_JoshSmith_Controls="clr-namespace:WPF.JoshSmith.Controls" 
             xmlns:local="clr-namespace:StoryMaker.Application" 
             mc:Ignorable="d" 
             x:Class="StoryMaker.Application.App"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
    	<ResourceDictionary>
    		<ResourceDictionary.MergedDictionaries>
    			<ResourceDictionary Source="/MoveResizeRotateWithAdorners;component/Resources/DesignerItem.xaml"/>
    			<ResourceDictionary Source="/MoveResizeRotateWithAdorners;component/Resources/ResizeRotateChrome.xaml"/>
    			<ResourceDictionary Source="/MoveResizeRotateWithAdorners;component/Resources/SizeChrome.xaml"/>
    			<ResourceDictionary Source="Resources/ShapeViewTemplatesResource.xaml"/>
    			<ResourceDictionary Source="Resources/Utilities.xaml"/>
    			<ResourceDictionary Source="/StoryMaker.BasicShapes;component/Themes/Generic.xaml"/>
    		</ResourceDictionary.MergedDictionaries>
    		<Style x:Key="ZoomOutItemStyle" TargetType="{x:Type ListBoxItem}">
    			<Setter Property="Background" Value="Transparent"/>
                <Setter Property="MinHeight" Value="{Binding Path=DataContext.MinimumHeight, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}" />
                <Setter Property="MinWidth" Value="{Binding Path=DataContext.MinimumWidth, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}" />
    			<Setter Property="LayoutTransform">
    				<Setter.Value>
    					<TransformGroup>
    						<ScaleTransform ScaleX="0.4" ScaleY="0.4"/>
    						<SkewTransform/>
    						<RotateTransform/>
    						<TranslateTransform/>
    					</TransformGroup>
    				</Setter.Value>
    			</Setter>
    			<Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
    			<Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
    			<Setter Property="Padding" Value="2,0,0,0"/>
    			<Setter Property="Template">
    				<Setter.Value>
    					<ControlTemplate TargetType="{x:Type ListBoxItem}">
    						<Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
    							<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" RenderTransformOrigin="0.5,0.5"/>
    						</Border>
    						<ControlTemplate.Triggers>
    							<Trigger Property="IsSelected" Value="true">
    								<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
    								<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
    							</Trigger>
    							<MultiTrigger>
    								<MultiTrigger.Conditions>
    									<Condition Property="IsSelected" Value="true"/>
    									<Condition Property="Selector.IsSelectionActive" Value="false"/>
    								</MultiTrigger.Conditions>
    								<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
    								<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
    							</MultiTrigger>
    							<Trigger Property="IsEnabled" Value="false">
    								<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
    							</Trigger>
    						</ControlTemplate.Triggers>
    					</ControlTemplate>
    				</Setter.Value>
    			</Setter>
    		</Style>
           
    		<ItemsPanelTemplate x:Key="HorizontalItemTemplate">
    			<StackPanel IsItemsHost="True" Orientation="Horizontal" HorizontalAlignment="Center"/>
    		</ItemsPanelTemplate>
    		<Style x:Key="SideButton" TargetType="{x:Type Button}">
    			<Setter Property="Template">
    				<Setter.Value>
    					<ControlTemplate TargetType="{x:Type Button}">
    						<Grid>
    							<Grid.RowDefinitions>
    								<RowDefinition Height="0.4*"/>
    								<RowDefinition Height="0.6*"/>
    							</Grid.RowDefinitions>
    							<VisualStateManager.VisualStateGroups>
    								<VisualStateGroup x:Name="CommonStates">
    									<VisualState x:Name="Normal"/>
    									<VisualState x:Name="MouseOver">
    										<Storyboard>
    											<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="MouseOverOverlay">
    												<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
    											</ObjectAnimationUsingKeyFrames>
    										</Storyboard>
    									</VisualState>
    									<VisualState x:Name="Pressed">
    										<Storyboard>
    											<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="MouseOverOverlay">
    												<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
    											</DoubleAnimationUsingKeyFrames>
    										</Storyboard>
    									</VisualState>
    									<VisualState x:Name="Disabled">
    										<Storyboard>
    											<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="regularPolygon">
    												<EasingColorKeyFrame KeyTime="0" Value="#FF606060"/>
    											</ColorAnimationUsingKeyFrames>
    										</Storyboard>
    									</VisualState>
    								</VisualStateGroup>
    							</VisualStateManager.VisualStateGroups>
    							<Rectangle Grid.RowSpan="2">
    								<Rectangle.Fill>
    									<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" SpreadMethod="Reflect">
    										<LinearGradientBrush.RelativeTransform>
    											<TransformGroup>
    												<ScaleTransform CenterY="0.5" CenterX="0.5"/>
    												<SkewTransform CenterY="0.5" CenterX="0.5"/>
    												<RotateTransform Angle="90" CenterY="0.5" CenterX="0.5"/>
    												<TranslateTransform/>
    											</TransformGroup>
    										</LinearGradientBrush.RelativeTransform>
    										<GradientStop Color="#FF708F8D" Offset="0"/>
    										<GradientStop Color="#FF90CAFF" Offset="1"/>
    									</LinearGradientBrush>
    								</Rectangle.Fill>
    							</Rectangle>
    							<Rectangle x:Name="MouseOverOverlay" Grid.RowSpan="2" Visibility="Hidden" Opacity="0.6" >
    								<Rectangle.Fill>
    									<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
    										<LinearGradientBrush.RelativeTransform>
    											<TransformGroup>
    												<ScaleTransform CenterY="0.5" CenterX="0.5"/>
    												<SkewTransform CenterY="0.5" CenterX="0.5"/>
    												<RotateTransform Angle="90" CenterY="0.5" CenterX="0.5"/>
    												<TranslateTransform/>
    											</TransformGroup>
    										</LinearGradientBrush.RelativeTransform>
    										<GradientStop Color="#FF7F86C2" Offset="1"/>
    										<GradientStop Color="#FF262A45"/>
    									</LinearGradientBrush>
    								</Rectangle.Fill></Rectangle>
    							<ContentPresenter x:Name="Content" HorizontalAlignment="Center" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Bottom" Visibility="Collapsed" Content="{TemplateBinding Content}" d:LayoutOverrides="VerticalAlignment, Width"/>
    							<ed:RegularPolygon x:Name="regularPolygon" HorizontalAlignment="Stretch" Height="10" InnerRadius="1" PointCount="3" Stretch="Fill" Width="18" Fill="Black" RenderTransformOrigin="0.5,0.5" Grid.Row="0" VerticalAlignment="Stretch" Grid.RowSpan="2">
    								<ed:RegularPolygon.RenderTransform>
    									<TransformGroup>
    										<ScaleTransform/>
    										<SkewTransform/>
    										<RotateTransform Angle="-90"/>
    										<TranslateTransform/>
    									</TransformGroup>
    								</ed:RegularPolygon.RenderTransform>
    							</ed:RegularPolygon>
    						</Grid>
    						<ControlTemplate.Triggers>
    							<Trigger Property="IsFocused" Value="True"/>
    							<Trigger Property="IsDefaulted" Value="True"/>
    							<Trigger Property="IsMouseOver" Value="True">
    								<Setter TargetName="MouseOverOverlay" Property="Visibility" Value="Visible" />
    							</Trigger>
    							<Trigger Property="IsPressed" Value="True"/>
    							<Trigger Property="IsEnabled" Value="False"/>
    						</ControlTemplate.Triggers>
    					</ControlTemplate>
    				</Setter.Value>
    			</Setter>
    		</Style>
    		<ItemsPanelTemplate x:Key="CanvasPanelTemplate">
    			<Canvas IsItemsHost="True" AllowDrop="True" />
    		</ItemsPanelTemplate>
            <DataTemplate DataType="common:PageCollection">
    		    <ListBox  ItemTemplate="{DynamicResource PageDataTemplate}" ItemsSource="{Binding }" ItemContainerStyle="{DynamicResource ZoomOutItemStyle}"/>
            </DataTemplate>
    		<DataTemplate DataType="common:Page">
    			<Grid>
    				<Grid.RowDefinitions>
    					<RowDefinition Height="*"/>
    					<RowDefinition Height="Auto"/>
    				</Grid.RowDefinitions>
    				<ListView Drop="CanvasItemControl_Drop" x:Name="CanvasItemControl" Grid.Row="0" Grid.Column="0" ItemsPanel="{DynamicResource CanvasPanelTemplate}" Grid.RowSpan="1" ItemsSource="{Binding Shapes}"  MinHeight="100" ItemTemplate="{DynamicResource CanvasShape}" AllowDrop="True" Background="#00000000" ItemContainerStyle="{DynamicResource ListViewItemStyle}" SelectionMode="Single" >			
					</ListView>
    				<TextBox Grid.Column="0" Grid.Row="1" TextWrapping="Wrap" d:LayoutOverrides="Height" Text="{Binding Text}" SpellCheck.IsEnabled="True" FontFamily="Euphemia" FontSize="18.667"/>
    			</Grid>
    		</DataTemplate>
         
    		<DataTemplate x:Key="BrushSelectionTemplate">
    			<Grid>
    				<ToggleButton IsChecked="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}}" >
    					<Rectangle Margin="4" Height="18" Width="18" Fill="{Binding}" />
    				</ToggleButton> 		
    			</Grid>
    		</DataTemplate>
    		<ItemsPanelTemplate x:Key="FlowPanelTemplate">
    			<WrapPanel Width="{Binding (FrameworkElement.ActualWidth), RelativeSource={RelativeSource AncestorType={x:Type ScrollContentPresenter}}}" ScrollViewer.VerticalScrollBarVisibility="Disabled" />
    		</ItemsPanelTemplate>
    		<Style x:Key="ListViewItemStyle" TargetType="{x:Type ListViewItem}">
                <Setter Property="Background" Value="Transparent" />
    			<Setter Property="Canvas.Left" Value="{Binding Left, Mode=TwoWay}"></Setter>
				<Setter Property="Canvas.Top" Value="{Binding Top, Mode=TwoWay}"></Setter>
    			<Setter Property="Template">
    				<Setter.Value>
    					<ControlTemplate TargetType="{x:Type ListViewItem}">
    						<Grid>
	    						<ContentControl Height="{Binding Height, Mode=TwoWay}" Width="{Binding Width, Mode=TwoWay}" Selector.IsSelected="{Binding IsSelected, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type ListViewItem}}}" DataContext="{Binding Content, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type ListViewItem}}}"
				                    Style="{StaticResource DesignerItemStyle}">
	    							<ContentPresenter IsHitTestVisible="False" x:Name="ContentHost" />			
								</ContentControl>
							</Grid>
    					</ControlTemplate>
    				</Setter.Value>
    			</Setter>
    		</Style>
        </ResourceDictionary>
         
    </Application.Resources>
</Application>
